<extend name="Public/base"/>
<block name="content">
    <form action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-block" style="margin-bottom: 10px;">
                <input type="text" name="title" lay-verify="required|title" required placeholder="请输入类名"
                       autocomplete="off" class="layui-input"><span id="sortmsg"></span>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</block>

<block name="js">
    <script src="__PUBLIC__/layui/layui.js"></script>
    <script>
        layui.use('form', function () {
            var data = {};
            var $ = layui.jquery;
            $('input[name="title"]').blur(function () {
                data.title = $('input[name="title"]').val();
                if (data.title == '' || data.title == null) {
                    $('#sortmsg').html('<font color="red">很抱歉！类名不能为空哦</font>')
                    return false;
                }
                $.post("{:U('Sort/checkSort')}", data, function (e) {
                    if (e.code == 1) {
                        $('#sortmsg').html('<font color="green">恭喜你！该类名可以使用</font>')
                    } else {
                        $('#sortmsg').html('<font color="red">很抱歉！该类名不可使用哦</font>')
                    }
                })
            })
        })
    </script>
</block>
